package com.ruoyi.factorydata.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.factorydata.domain.ProductionProjectProductionInfo;
import com.ruoyi.factorydata.domain.vo.ProductionProjectProductionInfoVo;
import com.ruoyi.factorydata.service.IProductionProjectProductionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产项目产品Controller
 *
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/projectproductioninfo/projectproductioninfo")
public class ProductionProjectProductionInfoController extends BaseController {
    @Autowired
    private IProductionProjectProductionInfoService productionProjectProductionInfoService;

    /**
     * 查询生产项目产品列表
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionProjectProductionInfo productionProjectProductionInfo) {
        startPage();
        List<ProductionProjectProductionInfoVo> list = productionProjectProductionInfoService.selectProductionProjectProductionInfoList(productionProjectProductionInfo);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setRows(list);
        tableDataInfo.setTotal(new PageInfo(list).getTotal());
        return tableDataInfo;
    }

    /**
     * 导出生产项目产品列表
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:export')")
    @Log(title = "生产项目产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionProjectProductionInfo productionProjectProductionInfo) {
        List<ProductionProjectProductionInfoVo> list = productionProjectProductionInfoService.selectProductionProjectProductionInfoList(productionProjectProductionInfo);
        ExcelUtil<ProductionProjectProductionInfoVo> util = new ExcelUtil<ProductionProjectProductionInfoVo>(ProductionProjectProductionInfoVo.class);
        util.exportExcel(response, list, "生产项目产品数据");
    }

    /**
     * 获取生产项目产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productionProjectProductionInfoService.selectProductionProjectProductionInfoById(id));
    }

    /**
     * 新增生产项目产品
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:add')")
    @Log(title = "生产项目产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionProjectProductionInfo productionProjectProductionInfo) {
        return toAjax(productionProjectProductionInfoService.insertProductionProjectProductionInfo(productionProjectProductionInfo));
    }

    /**
     * 修改生产项目产品
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:edit')")
    @Log(title = "生产项目产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionProjectProductionInfo productionProjectProductionInfo) {
        return toAjax(productionProjectProductionInfoService.updateProductionProjectProductionInfo(productionProjectProductionInfo));
    }

    /**
     * 删除生产项目产品
     */
    @PreAuthorize("@ss.hasPermi('projectproductioninfo:projectproductioninfo:remove')")
    @Log(title = "生产项目产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productionProjectProductionInfoService.deleteProductionProjectProductionInfoByIds(ids));
    }


}
